package eu.kuresson.tower.web;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.authorization.Action;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeAction;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;

@AuthorizeAction(action = Action.RENDER, roles = "ROLE_USER")
public class LoggedInPanel extends Panel {
	public LoggedInPanel(String id) {
		super(id);
		String userName = ((SpringWicketWebSession)getSession()).getUserName();
		add(new Label("userNameLabel", userName));
		add(new AjaxLink<Void>("logoutButton") {
			@Override
			public void onClick(AjaxRequestTarget target) {
				getSession().invalidateNow();
				setResponsePage(getApplication().getHomePage());
			}
		});
	}
}
